module.exports = function ($scope, $state, $modalInstance, $resource, $modal, toaster,bean) {

  $scope.bean = {
    'postflag' : ''
  }
  angular.extend($scope.bean, bean);
  console.log($scope.bean);

  $scope.loadlist = function () {
    $resource('/api/ac/mc/productShareService/findIdsList', {}, {}).save($scope.bean, function (res) {
      if (res.errcode == 0) {
        $scope.imgarr = res.data.result;
      } 
    });
  }
  $scope.loadlist();

  $scope.add = function (bean) {
    $scope.bean.postflag = '1';
    var modalInstance = $modal.open({
			template: require('../views/skwxPoster.html'),
			controller: 'skwxPoster',
			size: 'lg',
			resolve: {
				bean: function () {
					return $scope.bean;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function () {
      $scope.loadlist();
		});
  }

  $scope.bianji = function (ids) {
    $scope.bean.poster_ids = ids;
    $scope.bean.postflag = '2';
    var modalInstance = $modal.open({
			template: require('../views/skwxPoster.html'),
			controller: 'skwxPoster',
			size: 'lg',
			resolve: {
				bean: function () {
					return $scope.bean;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function () {
      $scope.loadlist();
		});
  }

  $scope.deletePoster = function (ids, index) {
    var param = {
      'product_code': bean.product_code,
      'company_code': bean.company_code,
      'share_id': ids
    }
    $resource('/api/ac/mc/productShareService/deleteSharePic1', {}, {}).save(param, function (res) {
			if (res.errcode === 0 && res.data == '1') {
        toaster.success({ title: '', body: '删除海报成功' });
        $scope.imgarr.splice(index, 1);
			} else {
				toaster.error({ title: '', body: res.errmsg });
			}
		});
  }

  $scope.cancel = function () {
    $modalInstance.close();
  }

};